define([], function() {
    'use strict';

    var Course = (function () {
        function Course(title, scoreFormula) {
            this._title = title;
            this._scoreFormula = scoreFormula;
            this._students = [];
        }

        Course.prototype.addStudent = function (student) {
            this._students.push(student);
        };

        Course.prototype.calculateResults = function () {
            var self = this;

            this._students.forEach(function (student) {
                student.totalScore = self._scoreFormula(student);
            });
        };

        Course.prototype.getTopStudentsByExam = function (count) {
            this._students.sort(function (firstStudent, secondStudent) {
                return secondStudent.exam - firstStudent.exam;
            });

            return this._students.slice(0, count);
        };

        Course.prototype.getTopStudentsByTotalScore = function (count) {
            this._students.sort(function (firstStudent, secondStudent) {
                return secondStudent.totalScore - firstStudent.totalScore;
            });

            return this._students.slice(0, count);
        };

        return Course;
    }());

    return Course;
});